<!DOCTYPE html>
<html lang="en" ng-app="weibo">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<div ng-controller="mainCtrl">
		<table border="1" cellpadding="0" cellspacing="0">
			<tr>
				<th>内容</th>
				<th>发布人</th>
				<th>发布时间</th>
			</tr>
			<tr ng-repeat="item in pageData">
				<td ng-bind-html="item.wb_text | replaceEmot"></td>
				<td>{{item.name}}</td>
				<td>{{item.created_at | date:'yyyy-MM-dd'}}</td>
			</tr>
			<tr>
				<td colspan="3">
					共<span ng-bind="recordCount"></span>条记录，<span ng-bind="pageIndex"></span>/<span ng-bind="pageCount"></span>页,每页显示
					<select ng-model="pageSize" ng-change="goPage(1)">
						<option ng-selected="10==pageSize">10</option>
						<option ng-selected="20==pageSize">20</option>
					</select>
					条
					<button ng-disabled="pageIndex==1" ng-click="goPage(1)">首页</button>
					<button ng-disabled="pageIndex==1" ng-click="goPage(pageIndex-1)">上页</button>
					<button ng-disabled="pageIndex==pageCount" ng-click="goPage(pageIndex+1)">下页</button>
					<button ng-disabled="pageIndex==pageCount" ng-click="goPage(pageCount)">尾页</button>
				</td>
			</tr>
		</table>
	</div>
	<script type="text/javascript" src="lib/angularjs/angular.js"></script>
	<script type="text/javascript" src="lib/angularjs/angular-sanitize.min.js"></script>
	<script>
		angular.module('weibo', [])
		.filter('replaceEmot',function($sce){
			return function(v){
				return $sce.trustAsHtml(v.replace('[生病]','<img src="faces/ee_8.png">'))			
			}
		})
		.constant('Config', {
			server: 'http://127.0.0.1:8001',
			url: {
				getWeibo: '/api/getWeibo'
			},
			apiUrl: function(key){
				return this.server + this.url[key];
			}
		})
		.controller('mainCtrl', ['$scope','$http','Config',function($scope,$http,Config){
			$scope.pageIndex = 1;
			$scope.pageSize = 10;
			$scope.pageCount = 0;
			$scope.pageSizes = [10,20,30,50];

			$scope.fetchData = function(){
				$http.get(Config.apiUrl('getWeibo'),{
					params: {
						pageIndex: $scope.pageIndex,
						pageSize: $scope.pageSize
					}
				}).then(function(res){
					$scope.pageData = res.data.pageData;
					$scope.recordCount = res.data.recordCount;
					$scope.pageCount = Math.ceil($scope.recordCount / $scope.pageSize);
				})				
			}

			$scope.goPage = function(p){
				$scope.pageIndex = p;
				$scope.fetchData()
			}

			$scope.fetchData()
		}])
	</script>
</body>
</html>